<form class="layui-form seller-form" action="">
    <div class="layui-tab">
        <ul class="layui-tab-title">
            <li><a href="{:url('tranForceButton')}">卡强制消费详情</a></li>
            <li><a href="{:url('tranForceTotal')}">卡强制消费统计(实时)</a></li>
            <li class="layui-this"><a href="{:url('tranForceKey')}">预扣>0,实际=0</a></li>
            <li><a href="{:url('tranForceDec')}">AMZ*Amazon Payments拒付统计</a></li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <div class="layui-inline" style="padding-left: 5px;">
                    <input type="text" name="user_name" lay-verify="title" placeholder="User Name" autocomplete="off"
                           class="layui-input">
                </div>
                <div class="layui-inline" style="padding-left: 5px;">
                    <input type="text" name="card_num" lay-verify="title" placeholder="Card Num" autocomplete="off"
                           class="layui-input">
                </div>
                <div class="layui-inline" style="padding-left: 5px;">
                    <input type="text" name="remark" lay-verify="title" placeholder="remark" autocomplete="off"
                           class="layui-input">
                </div>
                <div class="layui-inline" style="padding-left: 5px;">
                    <input type="text" name="datetime" id="datetime" placeholder="Start Time _ End Time" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-inline">
                    <div class="layui-input-block">
                        <button class="layui-btn layui-btn-sm" lay-submit lay-filter="*"><i class="iconfont icon-chaxun"></i>Search</button>
                        <button class="layui-btn layui-btn-sm" lay-submit lay-filter="user_data_update">Update Data</button>
                    </div>
                </div>
            </div>

        </div>
    </div>
</form>


<div class="table-body">
    <table id="dataTable" lay-filter="dataTable" ></table>
</div>
<script>
    layui.use(['form', 'laydate', 'table',], function () {
        var laydate = layui.laydate,
            form = layui.form,
            table = layui.table; //表格

        laydate.render({
            elem: '#datetime',
            range: '_',
            format: 'yyyy-MM-dd'
        });
        var tableIn = layui.table.render({
            elem: '#dataTable',
            height: 'full-99',
            cellMinWidth: '80',
            url: "{:url('tranForceKey')}",
            toolbar: '#toolbar',
            method:'POST',
            cols: [[
                { type: 'numbers'},
                { field: 'username', title: 'username',align:"left",width:200},
                { field: 'card_num', title: 'card_num',align:"left",width:200},
                { field: 'status', title: '卡状态', width:150 ,
                    templet:function (d) {
                        const status=   d.card_status;
                        var   html  =   '';
                        switch (status) {
                            case 1:
                                html = "<span style='color: green'>ACTIVE</span>";
                                break;
                            case 2:
                                html = "<span style='color: #6c757d'>SUSPENDED</span>";
                                break;
                            case 3:
                                html = "<span style='color: red'>CLOSED</span>";
                                break;
                            case 4:
                                html = "<span style='color: red'>Fraud</span>";
                                break;
                        }
                        return html;
                    }
                },
                {field: 'amount_auth', title: 'amount_auth($)', align:"right",
                    style:'color:#FF5722;font-weight:bold' , width:150,totalRow: true
                },
                {field: 'amount_post', title: 'amount_post($)', align:"right",
                    style:'color:#FF5722;font-weight:bold' , width:150,totalRow: true
                },
                { field: 'option', title: '备注', templet: function (d) {
                        var html = '<a class="layui-btn layui-btn-xs editDesc" data-id="' + d.id + '">备注</a>';
                        return html;
                    }, align: 'center',width: 70
                },
                { field: 'remark', align: 'left', title: 'Remark',width: 200},
                { field: 'ctime', align: 'center', title: '结算时间',width:180}
            ]],
            page: true,
            limit: 20,
            limits: [20,50,100,500,1000],
        });

        layui.form.on('submit(*)', function (data) {
            layui.table.reload('dataTable', {
                where: data.field
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        layui.form.on('submit(user_data_update)', function () {
            var loading =layer.load(1, {shade: [0.1,'#fff']});
            JsPost("{:url('upTranKey')}",'', function(res){
                layer.close(loading);
                if(res.code >0){
                    layer.msg(res.msg, { time: 1500 , icon:1}, function () {
                        tableIn.reload({
                            page:{
                                curr :1
                            }
                        });
                    });
                }else{
                    layer.msg(res.msg , {time:1500 , icon:2});
                }
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        $(document).on('click', '.editDesc', function () {
            var id = $(this).attr('data-id');
            JsGet("{:url('editTranKey')}?qz_id="+id, function(e){
                if(e.status == 1){
                    layer.open({
                        type: 1,
                        title: '预扣>0,实际=0,备注',
                        area: ['550px', '300px'], //宽高
                        content: e.datas,
                        btn:['Confirm','Close'],
                        yes:function (index,layero) {
                            var thedata = $('.operationForm').serialize();
                            JsPost('{:url("editTranKey")}', thedata,function (re) {
                                if(re.code >0){
                                    layer.msg(re.msg , {icon:1,time:1500});
                                    layer.close(index);
                                    tableIn.reload({
                                        page:{
                                            curr :1
                                        }
                                    });
                                }else{
                                    layer.msg(re.msg, {icon:2,time:1500});
                                }
                            });
                        }
                    });
                }else{
                    layer.msg(e.msg);
                }
            });
        });

    });
</script>